package com.yang.service.Impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yang.mapper.CommodityMapper;
import com.yang.entity.Commodity;
import com.yang.entity.PageBean;
import com.yang.service.CommodityService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CommodityImpl implements CommodityService {

    @Resource
    private CommodityMapper commodityMapper;

    @Override
    public PageBean<Commodity> getCommodityList(Integer pageNum, Integer pageSize, String commodityName) {
        // 使用pageHelper分页插件进行分页查询
        PageHelper.startPage(pageNum, pageSize);

        // 获取商品数据
        List<Commodity> commodityList = commodityMapper.getCommodityList(commodityName);
        Page<Commodity> page = (Page<Commodity>) commodityList;
        // 封装PageBean对象
        PageBean<Commodity> pageBean = new PageBean<>();
        pageBean.setTotal(page.getTotal());
        pageBean.setItems(page.getResult());
        return pageBean;
    }
}
